package com.example.hello.hello.activity;



import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.RadioGroup;

import com.example.hello.hello.R;
import com.example.hello.hello.base.BaseActivity;
import com.example.hello.hello.factory.FragmentFactory;

public class MainActivity extends BaseActivity {

    private FragmentManager fragmentManager;
    private RadioGroup mRadioGroup;

    @Override
    protected void initView(Bundle savedInstanceState) {

        mRadioGroup = (RadioGroup)findViewById(R.id.rg_tab);
//        mRadioGroup.
        setFragmentManager(1);
        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                setFragmentManager(checkedId);
            }
        });
    }

    public void setFragmentManager(int checkedId){
        fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        Fragment fragment = FragmentFactory.getInstanceByIndex(checkedId);
        fragmentTransaction.replace(R.id.content,fragment);
        fragmentTransaction.commit();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment;
    }

    public void onClickLeftBtn(){

    }
    public void onClickReghtBtn(){

    }


}
